/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cafe.Model.Utility;

import java.io.Serializable;

/**
 * info about a Database info and Database management system (DBMS)
 *
 * @author Deka
 */
public class DatabaseInfo implements Serializable {

    final static String SQLSERVER_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    final static String MYSQL_DRIVER = "com.mysql.jdbc.Driver";

    // <editor-fold defaultstate="collapsed" desc="Property">
    private String DBMSDriver; //class name of JDBC Driver
    private String DBMSName;
    private String server;
    private String port;
    private String username;
    private String password;
    private String dataBaseName;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Contructor">
    public DatabaseInfo() {
        this.DBMSDriver = MYSQL_DRIVER;
        this.DBMSName = "mysql";
        this.server = "localhost";
        this.port = "3306";
        this.dataBaseName = "cafe";
        this.username = "root";
        this.password = "";
    }

    public DatabaseInfo(String DBMSDriver, String DBMSName, String server, String port, String dataBaseName, String username, String password) {
        this.DBMSDriver = DBMSDriver;
        this.DBMSName = DBMSName;
        this.server = server;
        this.port = port;
        this.dataBaseName = dataBaseName;
        this.username = username;
        this.password = password;
    }

    public DatabaseInfo(DatabaseInfo dbi) {
        this.DBMSDriver = dbi.DBMSDriver;
        this.DBMSName = dbi.DBMSName;
        this.server = dbi.server;
        this.port = dbi.port;
        this.dataBaseName = dbi.dataBaseName;
        this.username = dbi.username;
        this.password = dbi.password;
    }

    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Method">
    /**
     *
     * @return short URL without username & password
     */
    public String getURL() {
        switch (this.DBMSName) {
            case "sqlserver":
                return "jdbc:" + this.getDBMSName() + "://" + this.getServer() + ":" + this.getPort() + ";databaseName=" + this.getDataBaseName() + "?useUnicode=true&characterEncoding=utf8";
            case "mysql":
                return "jdbc:" + this.getDBMSName() + "://" + this.getServer() + ":" + this.getPort() + "/" + this.getDataBaseName() + "?useUnicode=true&characterEncoding=utf8";
            default:
                return null;
        }
    }

    /**
     * 
     * @return full connection URL
     */
    public String getFullURL() {
        System.out.println("da su dung");
        return "jdbc:" + this.getDBMSName() + "://" + this.getServer() + ":" + this.getPort() + ";databaseName=" + this.getDataBaseName() + "?useUnicode=true&characterEncoding=utf8" + ";username=" + this.username + ";password=" + this.password;
    }

    public DatabaseInfo clone() {
        return new DatabaseInfo(this);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Get-Set Method">
    public String getDBMSDriver() {
        return DBMSDriver;
    }

    public void setDBMSDriver(String DBMSDriver) {
        this.DBMSDriver = DBMSDriver;
    }

    public String getDBMSName() {
        return DBMSName;
    }

    public void setDBMSName(String DBMSName) {
        this.DBMSName = DBMSName;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getUsername() {
        return this.username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String pass) {
        this.password = pass;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getDataBaseName() {
        return dataBaseName;
    }

    public void setDataBaseName(String dataBaseName) {
        this.dataBaseName = dataBaseName;
    }
    // </editor-fold>
    
  
}
